<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客注册页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">

</head>

<body>
    <div class="nav">
        <img src="pic/logo2.jpg" alt="">
        <span class="blog-title">Bitch I'm Taylor Swift!</span>
        <div class="space"></div>
    </div>

    <div class="container-login">
        <div class="login-dialog">
            <h3>注册</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" name="username" id="username" placeholder="请输入用户名">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" name="password" id="password" placeholder="请输入密码">
            </div>
            <div class="row">
                <button id="submit" onclick="register()">注册</button>
            </div>
        </div>
    </div>
    <script src="js/jquery.min.js"></script>
    <script>
        function register() {
            $.ajax({
                type: "post",
                url: "/user/register",
                contentType: "application/json",
                data: JSON.stringify({
                    "userName": $("#username").val(),
                    "password": $("#password").val()
                }),
                success: function (result) {
                    console.log(result);
                    if (result != null && result.code == 200 && result.data != null) {
                        console.log(result.data);
                        let userInfo = result.data;
                        //存储token
                        location.href = "blog_login.html";
                    } else {
                        alert("!!!");
                    }
                }

            });
        }
    </script>
</body>

</html>